const mongoose = require('mongoose');

// 定义用户数据的 Schema（结构 + 校验）
const novelSchema = new mongoose.Schema({
  title: { 
    type: String, 
    required:true,
  },
  cate_name: { 
    type: String, 
    required:true,
  },
  state: { 
    type: String, 
    required:true,
  },
  pub_date:{
    type: Date, 
    required:true
  },
  cover: { 
    type: String, 
    default:''
  },
  content: { 
    type: String, 
    default:''
  },
  userId: { 
    type: mongoose.Schema.Types.ObjectId, 
    ref: 'User',
    required: true
  },
  categoryId: {
    type: mongoose.Schema.Types.ObjectId, 
    ref: 'Category',
    required: true
  },
  word_count: {
    type: Number,
    default: 0
  },
  chapter_count: {
    type: Number,
    default: 0
  },
  last_update: {
    type: Date,
    default: Date.now
  }
});

// 创建并导出 Model（对应 MongoDB 的 "novels" 集合）
const Novel = mongoose.model('Novel', novelSchema);

module.exports = Novel;